package com.yangli.leecode.mashib.interview;

import java.util.Arrays;

/**
 * @Description
 * @Author liyang
 * @Date 2023/3/9 14:01
 */
public class ThirtySeven {
    public static void main(String[] args){
        System.out.println(ThirtySeven.minPeople(new int[]{1,1,2}));

    }

    public static int minPeople(int[] arr){
        if (arr == null || arr.length == 0) {
            return 0;
        }
        Arrays.sort(arr);
        int count = 1;
        int cur = arr[0];
        int ans = 0;
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] != cur) {
                ans += ((count + cur) / (cur + 1)) * (cur + 1);
                cur = arr[i];
                count = 1;
            } else {
                count++;
            }
        }
        return ans + ((count + cur) / (cur + 1)) * (cur + 1);
    }

}
